﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace LKVMLMADMIN.Controllers.Json
{
    public class BaseController : Controller
    {
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            string token = requestContext.HttpContext.Request.Headers["token"];
            var sessionService = new LKVService.SystemService();            
            if (token!=null)
            {
                var UserId = sessionService.GetUserIdBySession(token);
                HttpSessionStateBase session = requestContext.HttpContext.Session;
                if (UserId > 0)
                {
                    var UserService = new LKVService.User();                   
                    var Profile =UserService.findUserById(UserId);
                    if (Profile != null)
                        session.Add("UserByToken", Profile);                    
                }
                else
                {
                    session.Add("UserByToken", null);                    
                }
            }
            base.Initialize(requestContext);
        }
    }
}